<template>
  <div class="MerchantList">
    <h3 v-if="title">优选附近商家</h3>
    <div v-if="list.length > 0">
      <van-row
        class="MerchantList_item"
        v-for="(item, index) in list"
        :key="index"
      >
        <van-col span="6" @click="goToMerchantDetails(item.mid)">
          <img class="MerchantList_item_img" :src="$base.baseImg + item.logo" />
        </van-col>
        <van-col span="14" @click="goToMerchantDetails(item.mid)">
          <div class="MerchantList_item_cont">
            <h4 class="MerchantList_item_cont_title">
              {{ item.mName }}
            </h4>
            <p class="MerchantList_item_cont_price">
              ￥{{ (item.minPrice / 100).toFixed(2) }}起
            </p>
            <p class="MerchantList_item_cont_address">
              {{ item.address }}
            </p>
          </div>
        </van-col>
        <van-col
          span="4"
          class="MerchantList_item_address"
          @click="openLocation(item)"
        >
          <img src="@/assets/address.png" />
          <p v-if="item.distance > 1000">{{ item.distance / 1000 }}km</p>
          <p v-else>{{ item.distance }}m</p>
        </van-col>
      </van-row>
    </div>
    <van-empty v-else />
  </div>
</template>

<script lang="ts">
import { Vue, Component, Prop } from "vue-property-decorator";
import { Col, Row, Empty } from "vant";
Vue.use(Col);
Vue.use(Row);
Vue.use(Empty);
@Component({})
export default class MerchantList extends Vue {
  @Prop() list?: [];
  @Prop() title?: string;
  private goToMerchantDetails(e: number) {
    this.$router.push(`/myCard/${e}`);
  }

  private openLocation(e: any) {
    let that = this;
    this.$wx.ready(function () {
      that.$wx.openLocation({
        latitude: parseFloat(e.lat),
        longitude: parseFloat(e.lon),
        name: e.mName,
        address: e.address,
        scale: 25,
        infoUrl: "",
      });
    });
  }
}
</script>

<style lang="scss" scoped>
.MerchantList {
  width: 100%;
  padding: 20px;
  box-sizing: border-box;
  & > h3 {
    font-size: 35px;
    line-height: 1.5;
    padding-left: 10px;
    border-left: 5px solid #b99267;
    box-sizing: border-box;
    font-weight: normal;
    margin: 20px 0;
  }
  .MerchantList_item {
    width: 100%;
    overflow: hidden;
    background-color: #fff;
    border-radius: 10px;
    padding: 20px;
    box-sizing: border-box;
    margin-bottom: 20px;
    .MerchantList_item_img {
      width: 100%;
      height: 150px;
      display: block;
      border-radius: 5px;
    }
    .MerchantList_item_cont {
      padding-left: 10px;
      box-sizing: border-box;
      .MerchantList_item_cont_title {
        font-size: 30px;
        line-height: 1;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        color: #333;
        font-weight: normal;
      }
      .MerchantList_item_cont_price {
        font-size: 26px;
        line-height: 2;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        color: red;
        font-weight: normal;
      }
      .MerchantList_item_cont_address {
        font-size: 26px;
        line-height: 1;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        color: #333;
        font-weight: normal;
      }
    }
    .MerchantList_item_address {
      text-align: right;
      img {
        width: 30px;
        display: block;
        margin: 20px auto 0;
      }
      p {
        font-size: 24px;
        color: #343434;
        line-height: 2;
      }
    }
  }
}
</style>
